package com.fxm.controller;

import com.fxm.domain.User;
import com.fxm.returns.RespEntity;
import com.fxm.returns.RespTable;
import com.fxm.service.UserService;
import com.fxm.vo.MapVO;
import com.fxm.vo.param.LoginParam;
import com.fxm.vo.param.UserParam;
import com.fxm.vo.result.SexResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 用户管理 前端控制器
 * </p>
 *
 * @author fxm
 * @since 2021-02-04
 */
@RestController
@RequestMapping("/user")
@Slf4j
@Api(value = "用户管理", tags = "用户管理")
public class UserController {

    @Resource
    private UserService userService;

    @PostMapping("/login")
    @ApiOperation(value = "管理后台登陆功能")
    public RespEntity<User> login(@RequestBody LoginParam loginParam) {
        RespEntity<User> respEntity = userService.login(loginParam);
        return respEntity;
    }

    @GetMapping("/list")
    @ApiOperation(value = "用户列表")
    public RespTable<List<User>> queryAllUser(UserParam userParam) {
        RespTable<List<User>> respTable = userService.queryAllUser(userParam);
        return respTable;
    }

    @GetMapping("/chinaMap")
    @ApiOperation(value = "中国地图")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "String", name = "beginDate", value = "开始时间", required = false),
            @ApiImplicitParam(paramType = "query", dataType = "String", name = "endDate", value = "结束时间", required = false),
    })
    public RespEntity<List<MapVO>> chinaMap(@RequestParam(value = "beginDate", required = false) String beginDate,
                                            @RequestParam(value = "endDate", required = false) String endDate) {
        RespEntity<List<MapVO>> respEntity = userService.chinaMap(beginDate, endDate);
        return respEntity;
    }

    @GetMapping("/provinceMap")
    @ApiOperation(value = "省份地图")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "String", name = "province", value = "省份名称", required = true),
            @ApiImplicitParam(paramType = "query", dataType = "String", name = "beginDate", value = "开始时间", required = false),
            @ApiImplicitParam(paramType = "query", dataType = "String", name = "endDate", value = "结束时间", required = false),
    })
    public RespEntity<List<MapVO>> provinceMap(@RequestParam(value = "province", required = true) String province,
                                               @RequestParam(value = "beginDate", required = false) String beginDate,
                                               @RequestParam(value = "endDate", required = false) String endDate) {
        RespEntity<List<MapVO>> respEntity = userService.provinceMap(province, beginDate, endDate);
        return respEntity;
    }

    @GetMapping("/send")
    @ApiOperation(value = "发送短信验证码")
    @ApiImplicitParam(paramType = "query", dataType = "String", name = "mobile", value = "手机号", required = true)
    public RespEntity<Integer> sendMsg(@RequestParam(value = "mobile", required = true) String mobile) {
        RespEntity<Integer> respEntity = userService.sendMsg(mobile);
        return respEntity;
    }

    @GetMapping("/queryUserByIds")
    @ApiOperation(value = "按照ids获取用户信息")
    public RespEntity<List<User>> queryUserByIds(@RequestParam("ids") Integer[] ids) {
        RespEntity<List<User>> respEntity = userService.queryUserByIds(ids);
        return respEntity;
    }

    @GetMapping("/allUser")
    @ApiOperation(value = "全部用户信息")
    public RespEntity<List<User>> allUser() {
        RespEntity<List<User>> respEntity = userService.allUser();
        return respEntity;
    }

    @PostMapping("/ban")
    @ApiOperation(value = "封禁用户")
    @ApiImplicitParam(paramType = "query", dataType = "String", name = "province", value = "省份名称", required = true)
    public RespEntity banUser(@RequestParam(value = "id", required = true) Integer id) {
        RespEntity respEntity = userService.banUser(id);
        return respEntity;
    }

    @GetMapping("/sex")
    @ApiOperation(value = "用户性别统计")
    public RespEntity<SexResult> sexCount() {
        RespEntity<SexResult> respEntity = userService.querySexCount();
        return respEntity;
    }

    @GetMapping("/blacklist")
    @ApiOperation(value = "用户黑名单列表")
    public RespTable<List<User>> blackList(UserParam userParam) {
        RespTable<List<User>> respTable = userService.blackList(userParam);
        return respTable;
    }

    @PostMapping("/unseal")
    @ApiOperation(value = "用户解封")
    @ApiImplicitParam(paramType = "query", dataType = "Integer", name = "id", value = "用户id", required = true)
    public RespEntity unseal(@RequestParam("id") Integer id) {
        RespEntity respEntity = userService.unseal(id);
        return respEntity;
    }


}
